//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    // 上拉加载
    allGoodsData: [],
    pageIndex: 1,
    state: "",
    uid: "",
    userType: "",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var uid = wx.getStorageSync('uid');
    var userType = wx.getStorageSync('userType');
    this.setData({
      uid: uid,
      userType: userType,
    })
    this.GetGoodsListByType();
  },

  // 获取--平台严选产品
  GetGoodsListByType: function () {
    var that = this;
    var uid = this.data.uid;
    var userType = this.data.userType;
    var allGoodsData = this.data.allGoodsData;
    var pageIndex = this.data.pageIndex;
    var threegoods = [];
    wx.showLoading({
      title: '加载中',
      icon: 'success',
      duration: 2000
    })
    console.log("method=GetGoodsListByType&PageSize=10&PageIndex=" + pageIndex + "&Type=" + '7' + "&UID=" + uid)
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetGoodsListByType&PageSize=10&PageIndex=" + pageIndex + "&Type=" + '7' + "&UID=" + uid),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        threegoods = json.ThreeGoods;
        for (var i = 0; i < json.length; i++) {
          allGoodsData.push(json[i])
        }
        that.setData({
          allGoodsData: allGoodsData,
          threegoods: threegoods,
        })
        console.log(allGoodsData);
        // console.log(threegoods)
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading();

      }

    })
  },
  // 店铺
  storeTap: function () {
    var that = this;
    var businessId = this.data.businessId;
    wx.navigateTo({
      url: '/packageA/store/store?businessId=' + businessId,
    })
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.pageIndex++;
    this.GetGoodsListByType();
  },

  // 得到部落推荐产品列表
  // GetGoodsListByType: function () {
  //   wx.showLoading({
  //     title: '加载中',
  //     icon: 'success',
  //     duration: 2000
  //   })
  //   var that = this;
  //   var allGoodsData = this.data.allGoodsData;
  //   var pageIndex = this.data.pageIndex;
  //   wx.request({
  //     url: baseJs.api + baseJs.encryUrl("method=GetGoodsListByType&Type=3&PageSize=10&PageIndex=" + pageIndex),
  //     success: function (res) {
  //       var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
  //       for (var i = 0; i < json.length; i++) {
  //         allGoodsData.push(json[i])
  //       }
  //       that.setData({
  //         allGoodsData: allGoodsData,
  //       })
  //       console.log(allGoodsData);
  //       if (json.length == 10) {
  //         that.setData({
  //           state: 'loadMore',
  //         })
  //       } else if (json.length == 0 && pageIndex == 1) {
  //         that.setData({
  //           state: 'noData',
  //         })
  //       } else if (json.length < 10) {
  //         that.setData({
  //           state: 'noMore',
  //         })
  //       } else if (json.length == 0 && pageIndex > 1) {
  //         that.setData({
  //           state: 'noMore',
  //         })
  //       }
  //       wx.hideLoading();

  //     }

  //   })
  // },

})